package lysjmaster.base.file.upload.service;

import lombok.extern.slf4j.Slf4j;
import lysjmaster.base.common.spring.base.BaseService;
import lysjmaster.base.common.spring.pagination.PageVo;
import lysjmaster.base.common.web.Resp;
import lysjmaster.base.common.web.RespUtil;
import lysjmaster.base.file.upload.domain.UploadInfo;
import lysjmaster.base.file.upload.repository.UploadInfoRepository;
import lysjmaster.base.file.upload.vo.UploadRecordVo;
import lysjmaster.base.file.util.resp.MyPage;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ZhangWenJian
 * @data 2019/1/4--17:15
 * @description uoloadInfo 服务类
 */
@Slf4j
@Service
@Transactional
public class UploadInfoService implements BaseService<UploadInfo> {


    @Resource
    private UploadInfoRepository uploadInfoRepository;
    @Resource
    public UploadInfoMd5InfoRelationService uploadInfoMd5InfoRelationService;

    @Override
    public UploadInfoRepository getRepository() {
        return uploadInfoRepository;
    }

//    public Resp listRewrite(UploadInfo entity, PageVo pageVo){
//        MyPage<UploadInfo> page = new MyPage<>(list(entity,pageVo));
//        List<UploadInfo> uploadInfos = (List<UploadInfo>) page.getContent();
//        List<UploadRecordVo> uploadRecordVos = new ArrayList<>();
//        for (UploadInfo uploadInfo:uploadInfos){
//            UploadRecordVo uploadRecordVo = new UploadRecordVo(uploadInfo);
//            uploadRecordVo.setUploadRecordInfoVos(uploadInfoMd5InfoRelationService.getRepository().queryUploadRecordInfoVos(uploadRecordVo.getId()));
//            uploadRecordVos.add(uploadRecordVo);
//        }
//        page.setContent(uploadRecordVos);
//        return RespUtil.success(page);
//    }

    /**
     * @author ZhangWenJian
     * @date 2019/1/8 14:20
     * @title buildUploadInfo
     * @param uploaderId
     * @return com.lysj.admin.file.upload.domain.UploadInfo
     * @description uploadInfo 实体类构建类
     */
    public UploadInfo buildUploadInfo( String uploaderId,String uploadDetails,String project,String module,boolean result){
        UploadInfo uploadInfo = new UploadInfo(uploaderId,uploadDetails,project,module,result);
        uploadInfo = uploadInfoRepository.saveAndFlush(uploadInfo);
        return uploadInfo;
    }


    public UploadInfo changeUploadDetails(UploadInfo uploadInfo,String uploadDetails,boolean result){
        uploadInfo.setUploadDetails(uploadDetails);
        uploadInfo.setResult(result);
        uploadInfo = uploadInfoRepository.saveAndFlush(uploadInfo);
        return uploadInfo;
    }











}
